/*
* @Author: chenggh
* @Date: 2025-06-14
* @Link to Problem : https://oj.haizeix.com/problem/46
*/
#include <iostream>
using namespace std;
string s;
int dp[1005][1005] = {0};
int main(){
	cin >> s;
	int n = s.size();
	s.insert(s.begin(), '0'); // 1开始
	for(int i = 1; i <= n; i++){
		dp[i][i] = 0;
	}
	// 区间长度
	for(int l = 1; l <= n; l++){
		// 左指针
		for(int i = 1; i + l - 1 <= n; i++){
			int j = i + l - 1;
			if(dp[i + 1][j - 1] == 0 && s[i] == s[j]) dp[i][j] = 0;
			else {
				dp[i][j] = s.size();
				for(int k = i; k < j; k++){
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + 1);
				}
			}
		}
	}
	cout << dp[1][n] << endl;
	return 0;
}